package com.ning.weixin.utils;

/**
 * 积分随机产生工具
 *
 * @author Cyan
 * @Date:2018/12/12
 */
public class ScoreUtil {

    /**
     * 66的概率是15%
     */
    public static double rate0 = 0.15;
    /**
     * 88出现的概率为15%
     */
    public static double rate1 = 0.15;
    /**
     * 166出现的概率为25%
     */
    public static double rate2 = 0.25;
    /**
     * 188出现的概率为18%
     */
    public static double rate3 = 0.18;

    /**
     * 366出现的概率为10%
     */
    public static double rate4 = 0.10;

    /**
     * 388出现的概率为9%
     */
    public static double rate5 = 0.09;

    /**
     * 666出现的概率为5%
     */
    public static double rate6 = 0.05;

    /**
     * 888出现的概率为3%
     */
    public static double rate7 = 0.03;


    public static Integer scoreGet() {
        double randomNumber = Math.random();
        if (randomNumber >= 0 && randomNumber <= rate0) {
            return 66;
        } else if (randomNumber >= rate0 && randomNumber <= rate0 + rate1) {
            return 88;
        } else if (randomNumber > rate0 + rate1 && randomNumber <= rate0 + rate1 + rate2) {
            return 166;
        } else if (randomNumber > rate0 + rate1 + rate2 && randomNumber <= rate0 + rate1 + rate2 + rate3) {
            return 188;
        } else if(randomNumber > rate0 + rate1 + rate2 + rate3 && randomNumber <= rate0 + rate1 + rate2 + rate3 + rate4) {
            return 366;
        } else if(randomNumber > rate0 + rate1 + rate2 + rate3 + rate4 && randomNumber <= rate0 + rate1 + rate2 + rate3 + rate4 + rate5) {
            return 388;
        }
          else if (randomNumber > rate0 + rate1 + rate2 + rate3 + rate4 + rate5 && randomNumber <= rate0 + rate1 + rate2 + rate3 + rate4 + rate5+rate6) {
            return 666;
        } else if (randomNumber > rate0 + rate1 + rate2 + rate3 + rate4 + rate5+rate6 && randomNumber <= rate0 + rate1 + rate2 + rate3 + rate4 + rate5+rate6+rate7) {
            return 888;
        }
        return -1;
    }

    public static void main(String[] args) {
        System.out.println(ScoreUtil.scoreGet());
    }

}
